var hotspotGraphicLayer;
var hideAllDistrictLayer;
require([
    "dojo/on",
    "esri/SpatialReference",
    "esri/symbols/SimpleLineSymbol",
    "esri/symbols/SimpleFillSymbol",
    "esri/symbols/PictureMarkerSymbol",
    "esri/layers/GraphicsLayer",
    "esri/layers/FeatureLayer",
    "esri/graphic", "esri/Color",
    "esri/geometry/Point",
    "esri/geometry/Circle",
    "esri/InfoTemplate",
    "dojo/domReady!"
], function (
    on, SpatialReference, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol,
    GraphicsLayer, FeatureLayer, Graphic, Color, Point, Circle, InfoTemplate) {

    initHotSpot = function () {
        hotspotGraphicLayer = new GraphicsLayer({
            id: "hotspotGraphicLayer"
        });
        map.addLayer(hotspotGraphicLayer);
    }

    for (let key in listConfig) {
        const sub = listConfig[key]
        sub.forEach(item => {
            const div = $(`<div class="hotspotListItem">${item.label}</div>`)
            $(".hotspotList").append(div);
        })
    }
    $(".hotspotListItem").click(function (e) {
        let curItem = {}
        const curLabel = this.innerText
        listConfig.hotSpotList.forEach(item => {
            if (item.label === curLabel) {
                curItem = item
            }
        })
        doHotspot(curItem)
    })

    function doHotspot(item) {
        // closePanel()
        hotspotGraphicLayer.clear()
        window.csjDistrictGraphicLayer.hide()
        window.newCityDistrictGraphicLayer.hide()
        const point = new Point(item.x, item.y, shanghaiSpatialRef)
        const pictureSymbol = new PictureMarkerSymbol("img/marker/map-marker.png", 30, 30).setOffset(0, 15);
        const infoCont = `<div id='aroundSearchBtn' class='aroundSearchBtn'><img width='20px' src='img/icon-nearby.png'>周边查询</div>`;
        const infoTemplate = new InfoTemplate("<b>" + item.label + "</b>", infoCont);
        const graphic = new Graphic(point, pictureSymbol, {}, infoTemplate)
        hotspotGraphicLayer.add(graphic)

        aroundSearchCenterGraphic = graphic;

        map.infoWindow.hide();
        map.infoWindow.setContent(graphic.getContent());
        map.infoWindow.setTitle(graphic.getTitle());
        map.infoWindow.show(graphic.geometry);

        //增加长三角示范区范围
        if (item.label == "长三角示范区") {
            map.centerAndZoom(graphic.geometry, 1);
            if (!window.csjDistrictGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.csjDistrictGraphicLayer.show();
            }
        } else if (item.label == "虹桥商务区") {
            map.centerAndZoom(graphic.geometry, 2);
            if (!window.hqGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.hqGraphicLayer.show();
            }
        } else if (item.label == "临港新片区") {
            map.centerAndZoom(graphic.geometry, 1);
            if (!window.lingangGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.lingangGraphicLayer.show();
            }
        } else if (item.label == "迪士尼") {
            map.centerAndZoom(graphic.geometry, 4);
            if (!window.disneyGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.disneyGraphicLayer.show();
            }
        } else if (item.label == "花博会") {
            map.centerAndZoom(graphic.geometry, 4);
            if (!window.huaboGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.huaboGraphicLayer.show();
                window.huaboAir.show();

            }
        } else {
            if (!window.newCityDistrictGraphicLayer) {

            } else {
                hideAllDistrictLayer()
                window.newCityDistrictGraphicLayer.show();
            }
            map.centerAndZoom(graphic.geometry, 3);

        }
    }

    hideAllDistrictLayer = function () {
        window.newCityDistrictGraphicLayer.hide();
        window.hqGraphicLayer.hide();
        window.disneyGraphicLayer.hide();
        window.csjDistrictGraphicLayer.hide();
        window.lingangGraphicLayer.hide();
        window.huaboGraphicLayer.hide();
        window.huaboAir.hide();
    }


})